package com.firefly.web.controller.admin.mc;

import com.firefly.web.controller.admin.ConsoleApiRestController;
import com.firefly.dao.dto.CommonDto;
import com.firefly.dao.dto.mc.McMenuDto;
import com.firefly.dao.vo.mc.McMenuVo;
import com.firefly.service.command.mc.McMenuCommand;
import com.firefly.service.query.mc.McMenuQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

/**
 * @description: 小程序用户权限菜单
 * @author: lzg(萤火科技 ： 854378082 @ qq.com)
 * @date: 2023/1/31
 **/
@ConsoleApiRestController("mcmenu")
public class McMenuController {
    private final McMenuQuery menuQuery;
    private final McMenuCommand menuCommand;
    @Autowired
    public McMenuController(McMenuQuery menuQuery, McMenuCommand menuCommand) {
        this.menuQuery = menuQuery;
        this.menuCommand = menuCommand;
    }
    //	获取菜单树
    @GetMapping("tree")
    public Object getTree() {
        return menuQuery.listTree();
    }
    //	获取下拉菜单树
    @GetMapping("select")
    public Object getSelect() {
        return menuQuery.selectTree();
    }
    @GetMapping("detail")
    public McMenuVo postDetail(@Validated(CommonDto.showDetail.class) CommonDto request) {
        return menuQuery.detail(request);
    }
    @PostMapping("create")
    public boolean postCreate(@Validated(McMenuDto.create.class) McMenuDto request) {
        return menuCommand.create(request);
    }
    @PostMapping("update")
    public boolean postUpdate(@Validated(McMenuDto.update.class) McMenuDto request) {
        return menuCommand.update(request);
    }
    @PostMapping("remove")
    public Object postRemove(@Validated(CommonDto.removeDetail.class) CommonDto request) {
        return menuCommand.removeById(request.getDetailId());
    }
}
